<template>
  <view>
    <u-cell-group style="background-color: #fff">
      <u-cell
        title="编辑个人资料"
        :title-style="titleStyles"
        isLink
        @click="changeUserInfo"
      >
      </u-cell>
      <u-cell
        title="修改密码"
        :title-style="{
          ...titleStyles,
          marginLeft: '22rpx',
        }"
        isLink
        url="/pages/login/forget"
      >
      </u-cell>
      <u-cell
        title="邀请码"
        :title-style="{
          ...titleStyles,
          marginLeft: '19rpx',
        }"
      >
        <view slot="right-icon" style="display: flex; align-items: center">
          <text style="font-size: 28rpx; color: #50cca6">{{ id }}</text>
          <image
            style="width: 30rpx; height: 30rpx; margin-left: 28rpx"
            src="/static/user-center/setting/sort.png"
          ></image>
        </view>
      </u-cell>
      <u-cell
        title="章节自动购买"
        :title-style="{
          ...titleStyles,
          marginLeft: '25rpx',
        }"
      >
        <u-switch
          slot="right-icon"
          inactive-color="rgba(120,120,128,0.16)"
          v-model="autoBuy"
          @change="autoBuy_set"
        ></u-switch>
      </u-cell>

      <u-cell
        title="隐私协议"
        :title-style="{
          ...titleStyles,
          marginLeft: '25rpx',
        }"
        isLink
        url="/pages/privacy/index?key=privacy"
      >
      </u-cell>
      <u-cell
        title="未成年人保护协议"
        :title-style="{
          ...titleStyles,
          marginLeft: '19rpx',
        }"
        isLink
        url="/pages/privacy/index?key=teen_private"
      >
      </u-cell>
    </u-cell-group>
  </view>
</template>

<script>
import uActionSheet from "@/uni_modules/uview-ui/";
export default {
  data() {
    return {
      id: "666VIP",
      autoBuy: false,
      titleStyles: {
        marginLeft: "22rpx",
        fontSize: "30rpx",
        color: "#333333",
      },
    };
  },
  onLoad(option) {
    console.log(option.id);
    this.id = option.id - 0 + 10000;
    if (uni.getStorageSync("autoBuy") == "") {
      uni.setStorageSync("autoBuy", false);
    }
    this.autoBuy = uni.getStorageSync("autoBuy");
  },
  onShow() {
    if (!uni.getStorageSync("user")) {
      console.log("未登录", uni.getStorageSync("user"));
      uni.showToast({
        icon: "none",
        position: "bottom",
        title: "请重新登录",
      });
      uni.navigateBack({});
    } else {
      console.log("已登录", uni.getStorageSync("user"));
    }
  },
  methods: {
    // 设置自动购买
    autoBuy_set(value) {
      console.log(this.autoBuy);
      if (this.autoBuy) {
        uni.setStorageSync("autoBuy", value);
      } else {
        uni.setStorageSync("autoBuy", value);
      }
    },
    // 复制账号
    copy() {
      uni.setClipboardData({
        data: "" + this.id,
        success: () => {
          uni.showToast({
            icon: "none",
            title: "复制成功",
          });
        },
      });
    },
    // 跳转修改手机号页面
    changePhone() {
      uni.showToast({
        icon: "none",
        title: "暂不支持",
      });
      return;
      uni.navigateTo({
        url: "../changePhone/changePhone",
      });
    },
    // 跳转修改邮箱页面
    changeEmail() {
      uni.showToast({
        icon: "none",
        title: "暂不支持",
      });
      return;
      uni.navigateTo({
        url: "../changePhone/changePhone",
      });
    },
    // 跳转修改密码页面
    changePassword() {
      // uni.showToast({
      // 	icon: 'none',
      //     title: '暂不支持'
      // })
      // return;
      uni.navigateTo({
        url: "/pages/login/forget",
      });
    },
    changeUserInfo() {
      uni.navigateTo({
        url: "/pages/ucenter/uinfo/uinfo?edit=1",
      });
    },
  },
};
</script>

<style>
page {
  background-color: #f7f8fb;
}
.box {
  background: #fff;
  color: #000;
  display: flex;
  font-weight: 400;
  height: 116rpx;
  justify-content: space-between;
  line-height: 116rpx;
  margin-bottom: 20rpx;
  padding: 0 40rpx;
}
.title {
  font-size: 24rpx;
  color: #999999;
  line-height: 33rpx;
  display: inline-block;
  margin: 16rpx 24rpx;
}
</style>
